<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <button class="box">节流</button>
</body>
<script>
  const box = document.querySelector('.box')

  function throttle(fn, delay) {
    let timer
    return function () {
      if (timer) {
        return
      }
      timer = setTimeout(() => {
        fn()
        // console.log('222')
        timer = null
      }, delay)
    }
  }
  box.onclick = throttle(() => {
    console.log('123')
  }, 1000)
</script>

</html>